﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Storage;
using System.Text;
using Windows.Storage.Streams;
using System.Security;
using System.Runtime.InteropServices;
using Windows.Security.Cryptography;
using Windows.Storage.Pickers;
using Windows.UI;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Media.Animation;
using Windows.Data.Xml.Xsl;
using Windows.Data.Xml.Dom;
using System.Xml.Serialization;


// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace Pass
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        /// <summary>
        /// Varial que guarda a instancia do flyout para manipulacao dentro dessa classe
        /// </summary>
        Popup _pop;
        /// <summary>
        /// classe de controle das senhas 
        /// </summary>
        Recursos.Controle controle = new Recursos.Controle("senha.xml");

        public  MainPage()
        {
            this.InitializeComponent();
            PopulaMainPage();            
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

        }

        private void Button_Click_1(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
        	// TODO: Add event handler implementation here.
            if (_pop == null)
            {
                _pop = new Popup();
                Cadastro Teste = new Cadastro(_pop, this);
                var transitions = new TransitionCollection();
                transitions.Add(new PopupThemeTransition() { FromHorizontalOffset = 100, FromVerticalOffset = 0 });
                Teste.Height = 768;
                _pop.ChildTransitions = transitions;
                _pop.HorizontalOffset = 1366 - Teste.Width;
                _pop.VerticalOffset = 0;
                _pop.Child = Teste;
                _pop.Height = 768;
                this.BottomAppBar.IsOpen = false;
            }
            _pop.IsOpen = true;
        }
        /// <summary>
        /// preenche a mainpage com todas as senhas guardadas no senha.xml
        /// </summary>
        private void PopulaMainPage()
        {
            
            controle.OpenFileData();

            for (int x = 0; x < controle._ListaSenha.Count; x++)
            {
                BitmapImage bi = new BitmapImage(new Uri("ms-appx:///Assets/StoreLogo.png"));
                CampoSenha Teste = new CampoSenha(controle._ListaSenha[x]._Titulo, controle._ListaSenha[x]._obs, bi);
                var transitions = new TransitionCollection();
                transitions.Add(new PopupThemeTransition() { FromHorizontalOffset = 0, FromVerticalOffset = 100 });
                Teste.Transitions = transitions;
                gridCampo.Items.Add(Teste);
            }
            controle = null;
        }

        public void AddCompoSenha (ImageSource Souce, string Titulo, string Obs)
        {
            CampoSenha camposenha = new CampoSenha(Titulo, Obs, Souce);
            gridCampo.Items.Add(camposenha);
        }

    }
}
